package editor;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class DialogSalvaLivello extends JDialog implements ActionListener{
	private JTextField testo;
	private JLabel label;
	private JButton conferma;
	private JButton annulla;
	private EditorFrame ef;
	
	public DialogSalvaLivello(EditorFrame ef){
		this.ef = ef;
		testo = new JTextField(10);
		label = new JLabel("Inserisci nome livello");
		conferma = new JButton("Ok");
		conferma.addActionListener(this);
		annulla = new JButton("Annulla");
		annulla.addActionListener(this);
		this.setLayout(new FlowLayout());
		this.add(label);
		this.add(testo);
		this.add(conferma);
		this.add(annulla);
		this.setTitle("Salva livello");
		this.setSize(300,100);
		this.setLocation(500,300);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == conferma){
			if (!testo.getText().isEmpty()){
				ef.getEditor().setNome(testo.getText());
				ef.getEditor().salvaLivello();
			}
			this.dispose();
		}
		if (e.getSource() == annulla){
			if(ef.getEditor().isExit()){
				this.dispose();
				ef.dispose();
			}
			else{
				this.dispose();
			}
		}
	}

}
